package com.jie.myvhr.service;

import com.jie.myvhr.bean.Salary;
import com.jie.myvhr.mapper.SalaryMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @date 2019/7/2 -8:21
 */
@Service
@Transactional
public class SalaryService {
    @Resource
    private SalaryMapper salaryMapper;

    /**
     * 工资账套管理查询账套
     */
    public List<Salary> getAllSalary(){
        return salaryMapper.getAllSalary();
    }

    /**
     * 工资账套管理更新账套
     */
    public int updateSalary(Salary salary) {
        return salaryMapper.updateSalary(salary);
    }
    /**
     * 工资账套管理新增账套
     */
    public int addSalary(Salary salary) {
        return salaryMapper.addSalary(salary);
    }
    /**
     * 工资账套管理删除账套
     * -1表示有员工信息
     * 大于0表示删除成功
     */
    public int delSalary(String ids){
        String[] split = ids.split(",");
        //删除账套判断是否有员工信息 0 表示没有员工信息
        int empSalaryBySids = salaryMapper.getEmpSalaryBySids(split);
        if (empSalaryBySids==0){
            return salaryMapper.deleteSalary(split);
        }
       return -1;
    }
    /**
     * 员工工资管理修改账套
     */
    public int updateEmpSalary(Integer sid,Long eid){
        salaryMapper.deleteEmpSalaryByEid(eid);
        return salaryMapper.addSidAndEid(sid,eid);
    }
}
